package com.ft.springboottravel.service.impl;

import com.ft.springboottravel.bean.Category;
import com.ft.springboottravel.mapper.CategoryMapper;
import com.ft.springboottravel.service.CategoryService;
import com.ft.springboottravel.util.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    CategoryMapper categoryMapper;
    @Override
    public Pager<Category> selectAllCategoryList(String cateName, Integer currentPage,Integer pagersNumber) {
        Pager<Category> categoryPager = new Pager<>();
        categoryPager.setCurrentPage(currentPage);
        categoryPager.setPageSize(pagersNumber);
        System.out.println("准备获取所有的List集合");
        List<Category> categoryList = categoryMapper.selectAllCategoryList( cateName,  currentPage, pagersNumber);
        System.out.println("刚获取玩所有的list集合");
        categoryPager.setList(categoryList);
        System.out.println("准备获取Long");
        Long aLong = selectAllCategoryListToLong(cateName);
        System.out.println("获取完Long了");
        categoryPager.setTotal(aLong);
        return categoryPager;
    }

    @Override
    public Long selectAllCategoryListToLong(String cateName) {
        return categoryMapper.selectAllCategoryListToLong(cateName);

    }

    @Override
    public void addCategory(String cateName) {
        categoryMapper.addCategory(cateName);
    }

    @Override
    public Category selectCategoryByCateId(Integer cateId) {
        return categoryMapper.selectCategoryByCateId(cateId);
    }

    @Override
    public void editCategoryByCategory(Category category) {
        categoryMapper.editCategoryByCategory(category);
    }

    @Override
    public List<Category> selectCategoryList() {
        return categoryMapper.selectCategoryList();
    }


}
